package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.error.BusinessException;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import lombok.experimental.FieldNameConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description: 物资资料
 * @Author: Mr.Cao
 * @DateTime: 2021/11/9 18:20
 * BMW F750GS
 **/
@RestController
@RequestMapping("business/product/")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 分页 获取全部的物资信息 正常物资
     */
    //http://www.localhost:8989/business/product/findProductList?pageNum=1&pageSize=6&name=&categoryId=&supplier=&status=0
    @GetMapping("findProductList")
    public ResponseBean findProductList(@RequestParam Map queryMap){
       PageVO page =  productService.findProductList(queryMap);
        return ResponseBean.success(page);
    }
    /**
     * 物资审核通过
     * */
    //http://www.localhost:8989/business/product/publish/54
    @PutMapping("publish/{id}")
    public ResponseBean publish(@PathVariable long id){
         productService.publish(id);
        return ResponseBean.success();
    }
    /**
     * 物资恢复 回收站中恢复
     * */
    //http://www.localhost:8989/business/product/back/51
    @PutMapping("back/{id}")
    public ResponseBean back(@PathVariable long id){
        productService.back(id);
        return ResponseBean.success();
    }
    /**
     * 删除回收站的物资
     * */
    //http://www.localhost:8989/business/product/delete/51
    @PutMapping("delete/{id}")
    public ResponseBean delete(@PathVariable long id){
        productService.delete(id);
        return ResponseBean.success();
    }
    /**
     * 移除物资到回收站
     * */
    //http://www.localhost:8989/business/product/remove/37
    @PutMapping("remove/{id}")
    public ResponseBean remove(@PathVariable long id){
        productService.remove(id);
        return ResponseBean.success();
    }
    /**
     * 添加物资信息
     * */
    //http://www.localhost:8989/business/product/add
    @PostMapping("add")
    public ResponseBean add(@RequestBody ProductVO productVO){
        productService.add(productVO);
        return ResponseBean.success();
    }
    /**
     * 编辑物资资料是数据回显
     * */
    //http://www.localhost:8989/business/product/edit/37
    @GetMapping("edit/{id}")
    public ResponseBean edit(@PathVariable long id){
        ProductVO productVO = productService.edit(id);
        return ResponseBean.success(productVO);
    }
    /**
     * 更新物资资料
     * */
    //http://www.localhost:8989/business/product/update/55
    @PutMapping("update/{id}")
    public ResponseBean update(@PathVariable long id,@RequestBody ProductVO productVO){
         productService.update(id,productVO);
        return ResponseBean.success();
    }

    /**
     * 查询物资库存
     * */
    //http://www.localhost:8989/business/product/findProductStocks?pageSize=9&pageNum=1
    @GetMapping("findProductStocks")
    public ResponseBean findProductStocks(@RequestParam Map queryMap) throws BusinessException {
        PageVO pageVO =  productService.findProductStocks(queryMap);
        return ResponseBean.success(pageVO);
    }
}
